package cn.wangfeixiong.filter;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@Component
@RefreshScope
@ConfigurationProperties(prefix = "request.log")
public class RequestLogRuleProperties implements Serializable {

    private List<Rule> rules = new ArrayList<>();

    private Boolean print = true;

    public static final Rule DEFAULT_RULE = new Rule();

    @Data
    public static class Rule implements Serializable {
        private Boolean print = true;
        private String  urlPrefix = "/";
        private Boolean printRequestHeader = false;
        private Boolean printRequestBody = true;
        private Boolean printResponseHeader = false;
        private Boolean printResponse = true;
        private Integer requestBodyLimitSize = 1024 * 4;
        private Integer responseLimitSize = 1024 * 4;
    }


    public  Rule defaultRule() {
         DEFAULT_RULE.setPrint(this.print);
         return DEFAULT_RULE;
    }
}
